@extends('layout.personalInfo')
@section('title','添加地址')
@section('personalInfoContent')
	<div class="col-md-6 col-md-offset-2">
		<form action="/home/address/doadd" method="post">
		    <div class="form-group">
		        <label class="">收货人</label>
		        <input type="text" class="form-control" name="consignee" value="">
			</div>
			<div class="form-group">
			    <label for="exampleInputPassword1">联系方式</label>
			    <input type="text" class="form-control" name="phone">
			</div>

			    <div class="form-group">
		  
		    <label for="exampleInputPassword1">收货地址</label>
		    <div class="clearfix"></div>
		    
		    <div class="col-md-3" style="padding:0px">
		    	<select name="prov" style="height:34px;width:100%">
		    	<option value="0">请选择</option>
		    	@foreach($area as $k=>$v)
		    		<option value="{{$v->areaid}}">{{$v->areaname}}</option>
		    	@endforeach
		    	</select>
		    </div>
		    <div class="col-md-3 col-md-offset-1" style="padding:0px">
		    	<select name="city" id="city" style="height:34px;width:100%">
		    		<option value="0">请选择</option>
		    	</select>
		    </div>
		    <div class="col-md-3 col-md-offset-1" style="padding:0px">
		    	<select name="county" id="" style="height:34px;width:100%">
		    		<option value="0">请选择</option>
		    	</select>
		    </div>
		    <div>
		    	<label for="exampleInputPassword1">详细地址</label>
		    	<div class="clearfix"></div>
		    	<textarea name="detail" id="" cols="57" rows="4"></textarea>
		    </div>
		    </div>
		     <div class="clearfix"></div>
			
		    <div class="">
		        <label>
		            <input type="checkbox" name="isdefault" value="1"> 设为默认地址
		        </label>
		    </div>
		    <div class="clearfix"></div>
		    <div class="col-md-3 " style="margin:15px 0px;padding:0px;">
		    	{{csrf_field()}}
			    <button type="submit" class="btn btn-default"><h4>确认添加</h></button>
		    </div>
		</form>
	</div>
	<script type="text/javascript">
	

	//获取市级地址信息
	$('select[name=prov]').change(function(){
		//获取当前 id
		var pid = $(this).val();
		// alert(id);
		//发送ajax到
		$.get('/home/address/achieve',{'pid':pid},function(data){
			if(data){
				for(var i=0;i<data.length;i++){
					var id = data[i].areaid;
					var name = data[i].areaname;
					// console.log(id);
					var op = $('<option value="'+id+'">'+name+'</option>');
					$('select[name=city]').append(op);
				}
			}
		},'json');
	});

	$('select[name=city]').change(function(){
		//获取当前 id
		var pid = $(this).val();
		// alert(id);
		//发送ajax到
		$.get('/home/address/achieve',{'pid':pid},function(data){
			if(data){
				for(var i=0;i<data.length;i++){
					var id = data[i].areaid;
					var name = data[i].areaname;
					// console.log(id);
					var op = $('<option value="'+id+'">'+name+'</option>');
					$('select[name=county]').append(op);
				}
			}
		},'json');
	});
</script>
@endsection
